package MAgentAssignment.gui;

import MAgentAssignment.ontology.concepts.Airport;

import javax.swing.*;
import java.awt.*;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: Prageeth
 * Date: 2/16/12
 * Time: 8:56 PM
 * To change this template use File | Settings | File Templates.
 */
public class AirportIcon extends JComponent
{
    private Airport airport;
    private Vector<AirportStatusListener> airportStatusListeners = new Vector<AirportStatusListener>();

    public void init()
    {
        airport = new Airport();
    }

    public Airport getAirport()
    {
        return airport;
    }

    public void setAirport( Airport airport )
    {
        this.airport = airport;
    }

    @Override public void paint( Graphics g )
    {
        g.setColor( Color.ORANGE );
        if( airport != null && airport.getLocation() != null )
        {
            g.fillRect( airport.getLocation().getLocX(), airport.getLocation().getLocY(), FlightUtil.AIRPORT_ICON_WIDTH, FlightUtil.AIRPORT_ICON_HEIGHT );
            g.setColor( Color.BLUE );
            g.drawString( airport.getAirportName() + " " + String.valueOf(airport.getParkingSlots() - airport.getIncomingFlights().size()) + " Free", airport.getLocation().getLocX() + FlightUtil.AIRPORT_ICON_WIDTH, airport.getLocation().getLocY() + FlightUtil.AIRPORT_ICON_HEIGHT );
        }
    }

    private void fireStatusClosed()
    {
        for( AirportStatusListener airportStatusListener : airportStatusListeners )
        {
            airportStatusListener.closed();
        }
    }

    public void addAirportStatusListener( AirportStatusListener airportStatusListener )
    {
        airportStatusListeners.add( airportStatusListener );
    }

    public void removeAirportStatusListener( AirportStatusListener airportStatusListener )
    {
        airportStatusListeners.remove( airportStatusListener );
    }

    public void cancelAirport()
    {
        airportStatusListeners.clear();
    }
}
